package com.nhncorp.pleiades.msg;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.nhncorp.pleiades.client.LockService;
import com.nhncorp.pleiades.ens.EventMessage;

public class EventMessageParser implements MessageParser {
  
  public static final Log LOG = LogFactory
  .getLog(EventMessageParser.class.getName());

  public EventMessageParser() {
  }
  
  public boolean isValidMessage(Object message) {
    boolean isSuccess = false;
    if (((EventMessage) message).getEventType() == LockService.Events.NODE_ADDED
        .ordinal()) {
      isSuccess = true;
    } else if (((EventMessage) message).getEventType() == LockService.Events.NODE_REMOVED
        .ordinal()) {
      isSuccess = true;
    } else if (((EventMessage) message).getEventType() == LockService.Events.NODE_MODIFIED
        .ordinal()) {
      isSuccess = true;
    } else if (((EventMessage) message).getEventType() == LockService.Events.CONTENTS_CHANGED
        .ordinal()) {
      isSuccess = true;
    } else if (((EventMessage) message).getEventType() == LockService.Events.MASTER_FAILOVER
        .ordinal()) {
      isSuccess = true;
    } else if (((EventMessage) message).getEventType() == LockService.Events.LOCK_EXPIRED
        .ordinal()) {
      isSuccess = true;
    } else if (((EventMessage) message).getEventType() == LockService.Events.CLIENT_EXPIRED
        .ordinal()) {
      isSuccess = true;
    } else {
      LOG.debug("message format is wrong");
    }
    return isSuccess;
  }

}
